//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    objArr:[
      {
        src:"../../images/tu1.png",
        title:"女童加厚棉服棉衣",
        zhe:"3.8折",
        qi:"人 气3051",
        price1:"￥124.70",
        price2:"￥328", 
        text1:"防风保暖",
        text2:"小马图案设计"     
      },
      {
        src:"../../images/tu2.png",
        title:"女童保暖长袖棉衣",
        zhe:"3.8折",
        qi:"人 气1656",
        price1:"￥126",
        price2:"￥328",
        text1:"满印卡通印花",
        text2:"薄绒风衣"       
      }, 
      {
        src:"../../images/tu3.png",
        title:"特惠女童冬装羽绒背心",
        zhe:"3.9折",
        qi:"人 气889",
        price1:"￥45.4",
        price2:"￥117",
        text1:"实惠款",
        text2:"本款尺码偏小"      
      }, 
      {
        src:"../../images/tu4.png",
        title:"女童中长款外套风衣",
        zhe:"2.1折",
        qi:"人 气898",
        price1:"￥83.40",
        price2:"￥398",
        text1:"加厚保暖",
        text2:"卡通小马"       
      },
    ],
  },
  handle(e){
    console.log(e);
    console.log(e.currentTarget.id);
    console.log(e.currentTarget.dataset.obj);
    let obj = e.currentTarget.dataset.obj;
    // 事件跳转
    // wx.switchTab({
    //   url: '/pages/about/about',
    // })

    // wx.reLaunch({
    //   url: '/pages/about/about'+"?name="+obj.name+"&age="+obj.age+"&sex="+obj.sex,
    // })

    // 缓存传值

    wx.setStorageSync('obj', e.currentTarget.dataset.obj);

  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
